{include file='public/head'}
<body>
<style type="text/css" media="screen">
    header {
        color: black;
    }

    .bianti td {
        text-align: center
    }
    .x-body {
        min-width: 1100px;
    }

    body {
        overflow-x: scroll;
    }
    a {
        cursor:pointer;
    }
    .bdel{
        color: #FF5722;
    }
    .btool{
        color: #1E9FFF;
    }
    .bupload{
        color: #5FB878;
    }
    .layui-table img {
        max-width: 150px !important;
        width: 150px;
        height: 100px;
    }
    .btdiv {
        width: 150px;
        float: left;
        margin-right: 10px;
        margin-bottom: 10px;
        border: 1px solid silver;
    }
    .choose{
        float: left;
        margin-left: auto !important;
    }
    .chooseimg{
        float: left;
        margin-left: auto !important;
        width: 33%;
    }
</style>
<div class="x-body">
    <form class="layui-form" id='mainForm' enctype="multipart/form-data" method="post" action="productEdit">
        <div class="layui-form-item">

            <input type="hidden" name="id" id="id" value="{$Think.get.id}">
            <input type="hidden" name="lang" id="lang" value="{$Think.get.lang}">
            <table class="layui-table">
                <colgroup>
                    <col width="10%">
                    <col>
                    <col width="10%">
                    <col>
                    <col width="10%">
                    <col>
                </colgroup>
                <thead>
                    <tr>
                        <th colspan="6" style="text-align: center">基本信息</th>
                    </tr>
                </thead>
                <tbody>
                <tr>
                    <td><b style="color:red">*</b>产品名称</td>
                    <td colspan="5">
                        <input type="text" id="proname" name="proname" lay-verify="required" autocomplete="off"
                               placeholder="请输入产品名称" class="layui-input" value="{$productInfo.proname}">
                    </td>
                </tr>

                <tr>
                    <td><b style="color:red">*</b>产品分类</td>
                    <td>
                        <select lay-filter="categoryname" name="bcate_id" id='bcate_id' lay-verify="required" lay-search>
                            <option value="">请先选择分类</option>
                            {volist name='category' id='vo'}
                            {php}
                            if($vo['bname'] == $productInfo['bname'] && $vo['platform'] == $productInfo['platform']){
                            {/php}
                            <option value="{$vo.id}" title="{$vo.platform}" selected>{$vo.bname}--{$vo.platform}</option>
                            {php}}else{{/php}
                            <option value="{$vo.id}" title="{$vo.platform}">{$vo.bname}--{$vo.platform}</option>
                            {php}}{/php}
                            {/volist}
                        </select>
                        <input type="hidden" id="platform" value="{$productInfo.platform}">
                        <input type="hidden" id="bname" name="bname" value="{$productInfo.bname}--{$productInfo.platform}">
                    </td>
                    <td>品牌</td>
                    <td colspan="3">
                        <input type="text" id="brand" name="brand" autocomplete="off" value="{$productInfo.brand}"
                               placeholder="请输入产品品牌" class="layui-input">
                    </td>
                </tr>

                <tr>
                    <td>SKU码</td>
                    <td>
                        <input type="text" id="skucode" name="skucode" autocomplete="off"
                               placeholder="请输入SKU码" class="layui-input" value="{$productInfo.skucode}">
                        <input type="hidden" id="oldsku" name="oldsku" value="{$productInfo.skucode}">
                    </td>
                    <td>产品编号</td>
                    <td>
                        <input type="text" id="code" name="code" autocomplete="off" class="layui-input"
                               value="{$productInfo.code}" readonly>
                    </td>
                    <td>库&nbsp;&nbsp;&nbsp;存</td>
                    <td>
                        <input type="number" id="kucun" name="kucun" autocomplete="off" size="30" min="0"
                               placeholder="请输入库存" class="layui-input" value="{$productInfo.kucun}">
                    </td>
                </tr>

                <tr>
                    <td>币&nbsp;&nbsp;&nbsp;种</td>
                    <td>
                        <input type="text" id="coin" name="coin" autocomplete="off" size="30"
                               placeholder="请输入币种" class="layui-input" value="{$productInfo.coin}">
                    </td>
                    <td>默认价格</td>
                    <td>
                        <input type="number" id="price" name="price" autocomplete="off" size="30" step="0.001"
                               min="0" value="{$productInfo.price}" placeholder="请输入默认价格" class="layui-input">
                    </td>
                    <td>销售价格</td>
                    <td>
                        <input type="number" id="saleprice" name="saleprice" autocomplete="off" size="30"
                               step="0.001" min="0" value="{$productInfo.saleprice}"
                               placeholder="请输入销售价格" class="layui-input">
                    </td>
                </tr>

                <tr>
                    <td>运&nbsp;&nbsp;&nbsp;费</td>
                    <td>
                        <input type="number" id="carriage" name="carriage" autocomplete="off" size="30"
                               step="0.001" min="0" value="{$productInfo.carriage}"
                               placeholder="请输入运费" class="layui-input">
                    </td>
                    <td>成本价￥</td>
                    <td>
                        <input type="number" id="cost" name="cost" autocomplete="off" size="30"
                               step="0.001" min="0" value="{$productInfo.cost}"
                               placeholder="请输入成本价" class="layui-input">
                    </td>
                    <td>重&nbsp;&nbsp;&nbsp;量(g)</td>
                    <td>
                        <input type="number" id="weight" name="weight" autocomplete="off" size="30" min="0"
                               placeholder="请输入产品重量" class="layui-input" value="{$productInfo.weight}">
                    </td>
                </tr>

                <tr>

                    <td><b style="color:red">*</b>英文简称</td>
                    <td>
                        <input type="text" id="english" name="english" autocomplete="off" lay-verify="required"
                               placeholder="请输入报关英文简称" class="layui-input" value="{$productInfo.english}"
                               onkeyup="this.value=this.value.replace(/[^a-zA-Z]/g,'')">
                    </td>
                    <td>中文简称</td>
                    <td>
                        <input type="text" id="chinese" name="chinese" autocomplete="off" value="{$productInfo.chinese}"
                               placeholder="请输入报关中文简称" class="layui-input" onkeyup="this.value=this.value.replace(/[^\u4e00-\u9fa5]/g,'')">
                    </td>
                    <td>海关编码</td>
                    <td>
                        <input type="text" id="hscode" name="hscode" autocomplete="off" value="{$productInfo.hscode}"
                               placeholder="请输入海关编码" class="layui-input">
                    </td>
                </tr>

                <tr>
                    <td>原产国</td>
                    <td>
                        <input type="text" id="origin" name="origin" autocomplete="off" value="{$productInfo.origin}"
                               placeholder="请输入原产国英文" class="layui-input" onkeyup="this.value=this.value.replace(/[^a-zA-Z]/g,'')">
                    </td>
                    <td>厂商名称</td>
                    <td>
                        <input type="text" id="facturer" name="facturer" autocomplete="off"
                               placeholder="请输入厂商名称" class="layui-input" value="{$productInfo.facturer}">
                    </td>
                    <td>厂商编号</td>
                    <td>
                        <input type="text" id="number" name="number" autocomplete="off" value="{$productInfo.number}"
                               placeholder="请输入厂商编号" class="layui-input">
                    </td>
                </tr>

                <tr>

                    <td>适用人群</td>
                    <td>
                        <input type="text" id="department" name="department" autocomplete="off"
                               value="{$productInfo.department}" placeholder="请输入适用人群" class="layui-input">
                    </td>
                    <td>珠宝类型</td>
                    <td>
                        <input type="text" id="gem" name="gem" autocomplete="off" value="{$productInfo.gem}"
                               placeholder="请输入珠宝类型" class="layui-input">
                    </td>
                    <td>金属材质</td>
                    <td>
                        <input type="text" id="metal" name="metal" autocomplete="off" value="{$productInfo.metal}"
                               placeholder="请输入金属材质" class="layui-input">
                    </td>
                </tr>

                <tr>
                    <td>材料</td>
                    <td>
                        <input type="text" id="material" name="material" autocomplete="off"
                               value="{$productInfo.material}" placeholder="请输入材料" class="layui-input">
                    </td>
                    <td>包装材料</td>
                    <td>
                        <input type="text" id="package" name="package" autocomplete="off" value="{$productInfo.package}"
                               placeholder="请输入包装材料" class="layui-input">
                    </td>
                </tr>

                <tr>
                    <td>来&nbsp;&nbsp;&nbsp;源</td>
                    <td colspan="5">
                        <textarea id="fromurl" name="fromurl" placeholder="请输入产品来源"
                                  class="layui-textarea">{$productInfo.fromurl}</textarea>
                    </td>
                </tr>

                <tr>
                    <td>卖&nbsp;&nbsp;&nbsp;点</td>
                    <td colspan="5">
                        <textarea id="sketch" name="sketch" placeholder="请输入卖点"
                                  class="layui-textarea">{$productInfo.sketch}</textarea>
                    </td>
                </tr>

                <tr>
                    <td>关键词</td>
                    <td colspan="5">
                        <textarea id="keywords" name="keywords" placeholder="请输入关键词"
                                  class="layui-textarea">{$productInfo.keywords}</textarea>
                    </td>
                </tr>

                <tr>
                    <td>产品描述</td>
                    <td colspan="5">
                        <textarea id="content" name="content" placeholder="请输入产品描述"
                                  class="layui-textarea">{$productInfo.content}</textarea>
                    </td>
                </tr>

                </tbody>
            </table>
        </div>
        <div class="layui-form-item">
            <table class="layui-table">
                <thead>
                <tr>
                    <th colspan="3" style="text-align: center">主产品图片</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td style="width: 100px;text-align: center">
                        <button type="button" class="layui-btn" id="jiaimg">新增图片</button>
                    </td>
                    <td style="text-align: center">
                        <div id="productimg">
                            {volist name="productInfo['imgs']" id='vo'}
                            <input name="resource[]" type="hidden" value="{$vo['resource']['id']}"/>
                            <div class="btdiv">
                                <input name="pname[]" type="hidden" id="pname[]" class="name"
                                       value="{$vo['resource']['name']}"/>
                                <input name="proimg[]" type="hidden" id="proimg[]" class="path"
                                       value="{$vo['resource']['path']}"/>
                                <input name="psize[]" type="hidden" id="psize[]" class="size"
                                       value="{$vo['resource']['size']}"/>
                                <input name="ppostfix[]" type="hidden" id="ppostfix[]" class="postfix"
                                       value="{$vo['resource']['postfix']}"/>
                                <input name="poriginal[]" type="hidden" id="poriginal[]" class="original"
                                       value="{$vo['resource']['original']}"/>
                                <img src="{$vo['resource']['path']}" onclick="previewImg(this)">

                                <input type="number" name="px[]" required placeholder="排序从小到大"
                                       class="layui-input" style="height: 25px;" value="{$vo.px}" min="0">
                                <a class="bupload chooseimg"
                                   href="uploadImg.html?filename={$vo['resource']['path']}">下载</a>
                                <a href="javascript:void(0);" class="bdel chooseimg" name="delimg">删除</a>
                                <a class="btool chooseimg"
                                   onclick="p_admin_show('去水印','imgtool.html?img={$vo[\'resource\'][\'path\']}')">去水印</a>
                            </div>
                            {/volist}
                        </div>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
        <div class="layui-form-item">
            <table class="layui-table bianti" id="mdiv">
                <colgroup>
                    <col>
                    <col width="12%">
                    <col width="12%">
                    <col width="12%">
                    <col width="12%">
                    <col width="12%">
                    <col width="12%">
                </colgroup>
                <thead>
                <tr><th colspan="8" style="text-align: center">商品变体与价格</th></tr>
                </thead>
                <tbody>
                <tr>
                    <th style="text-align: center"><b style="color:red">*</b>产品类名</th>
                    <th colspan="7">
                        <select name="bttname" id='bttname' lay-verify="required">
                            <option value="">请选择产品类名</option>
                            <option value="Color" {if $productInfo.btname eq 'Color'} selected {/if}>Color</option>
                            <option value="Size" {if $productInfo.btname eq 'Size'} selected {/if}>Size</option>
                            <option value="ColorSize" {if $productInfo.btname eq 'ColorSize'} selected {/if}>ColorSize</option>
                        </select>
                    </th>
                </tr>
                <tr>
                    <td>
                        <button type="button" class="layui-btn" style="background-color: #FFB800"
                                onClick="addimg();">新增变体
                        </button>
                    </td>
                    <td><b style="color: #1E9FFF">统一销售价格：</b></td>
                    <td>
                        <input class="layui-input" name="zbtsaleprice" type="number" id="zbtsaleprice" min="0"
                               step="0.01" onChange="plprice(this.form)">
                    </td>
                    <td></td>
                    <td><b style="color: #1E9FFF">统一库存数量：</b></td>
                    <td>
                        <input class="layui-input" name="plbtkucun" type="number" id="plbtkucun" min="0"
                               onChange="plkucun(this.form)">
                    </td>
                    <td style="width: 70px"></td>
                </tr>
                <tr style="background-color: #F2F2F2">
                    <td><span style="color: red">*</span>变体名，双变体用","隔开</td>
                    <td>默认价格</td>
                    <td><span style="color: red">*</span>销售价格</td>
                    <td>成本价</td>
                    <td>运费</td>
                    <td>库存数量</td>
                    <td style="width: 70px">操作</td>
                </tr>
                </tbody>
                {php}$m=0;{/php}
                {volist name="productInfo['shuxing']" id='vo'}
                {php}$m++;{/php}
                <tbody>
                <tr>
                    <td>
                        <div style="float: left;width: 85%">
                            <input type="text" id="btname[]" name="btname[]" class="layui-input"
                                   value="{$vo.cname}">
                        </div>
                        <div style="float: right;width: 10%;">
                            <input type="hidden" name="btname_id[]" id="btname_id[]" value="{$vo.btname_id}">
                            <a href="javascript:void(0);" class="layui-btn layui-btn-xs layui-btn-normal choose" onclick="btchoose(this)">选择</a>
                            <a href="javascript:void(0);" class="layui-btn layui-btn-xs layui-btn-primary choose" onclick="cbtname(this)">清除</a>
                        </div>
                    </td>
                    <td>
                        <input type="number" id="btprice[]" name="btprice[]" class="layui-input" min="0"
                               value="{$vo.price}" step="0.01">
                    </td>
                    <td>
                        <input type="number" id="btsaleprice[]" name="btsaleprice[]" class="layui-input" min="0"
                               lay-verify="required" value="{$vo.saleprice}" step="0.01">
                    </td>
                    <td>
                        <input type="number" id="bcost[]" name="bcost[]" class="layui-input" min="0"
                               value="{$vo.cost}" step="0.01">
                    </td>
                    <td>
                        <input type="number" id="bcarriage[]" name="bcarriage[]" class="layui-input" min="0"
                               value="{$vo.carriage}" step="0.01">
                    </td>
                    <td>
                        <input type="number" id="btkucun[]" name="btkucun[]" class="layui-input" min="1"
                               value="{$vo.kucun}">
                    </td>
                    <td rowspan="2">
                        <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="bpull({$m})">
                            <i class="layui-icon">&#xe64c;</i>主图拉取
                        </button>
                        <br><br>
                        <button type="button" class="layui-btn layui-btn-sm" id="bupload{$m}">
                            <i class="layui-icon">&#xe67c;</i>新增图片
                        </button><br><br>
                        <input name="imgid[]" type="hidden" id="imgid[]" value="{$m}"/>
                        <a class="layui-btn layui-btn-sm layui-btn-danger" href="javascript:void(0);" name="rmlink">
                            <i class="layui-icon">&#xe640;</i>删除变体
                        </a>
                    </td>
                </tr>
                <tr>
                    <td colspan="6">
                        <div id="myimg{$m}">
                            {if isset($vo['imgs'])}
                            {volist name="vo['imgs']" id='v'}
                            <input name="resource[]" type="hidden" value="{$v.id}"/>
                            <div class="btdiv">
                                <input name="btimg{$m}[]" type="hidden" id="btimg{$m}[]" value="{$v.path}"/>
                                <input name="bname{$m}[]" type="hidden" id="bname{$m}[]" value="{$v.name}"/>
                                <input name="bsize{$m}[]" type="hidden" id="bsize{$m}[]" value="{$v.size}"/>
                                <input name="bpostfix{$m}[]" type="hidden" id="bpostfix{$m}[]" value="{$v.postfix}"/>
                                <input name="boriginal{$m}[]" type="hidden" id="boriginal{$m}[]" value="{$v.original}"/>
                                <img src="{$v.path}" style="float: left;" onclick="previewImg(this)">
                                <input type="number" name="bpx{$m}[]" required placeholder="排序从小到大"
                                       class="layui-input" style="height: 25px;" value="{$v.px}" min="0">
                                <a class="bupload chooseimg"  href="uploadImg.html?filename={$v.path}">下载</a>
                                <a href="javascript:void(0);" class="bdel chooseimg" name="delimg">删除</a>
                                <a class="btool chooseimg" onclick="p_admin_show('去水印','imgtool.html?img={$v.path}')" >去水印</a>
                            </div>
                            {/volist}
                            {/if}
                        </div>
                    </td>
                </tr>
                </tbody>
                {/volist}
            </table>
            <input type="hidden" name="num" id="num" value="{++$m}">
        </div>


        <div class="layui-form-item" style="text-align: center">
            <div>
                <input type="hidden" name="guid" id="guid" value="{$productInfo.guid}">
                <input type="hidden" id="company_id" name="company_id" value="{$Think.get.company_id}">
                <button class="layui-btn" style="width: 100%" lay-submit="" lay-filter="toSubmit"
                        onclick="ajaxSubmitForm();">提交
                </button>
            </div>
        </div>

    </form>
</div>

<input type="hidden" id="btnamecon" value="">
<input type="hidden" id="btnameids" value="">
</body>
{include file='public/foot'}
<script type="text/javascript" src="__static__/js/ajaxfileupload.js"></script>
<script type="text/javascript">
    var form = layui.form;
    var layer = layui.layer;
    var upload = layui.upload;
    var id = $("#num").val();
    form.on('select(categoryname)', function (data) {
        $("#platform").val(data.elem[data.elem.selectedIndex].title);
        $("#bname").val(data.elem[data.elem.selectedIndex].text);
    });

    function cbtname(obj){
        $(obj).parent().find('input').val('');
        $(obj).parent().prev().find('input').val('');
    }

    function btchoose(obj){
        $("#btnameids").val("");
        $("#btnamecon").val("");
        var id = $(obj).parent().find('input').val();
        //iframe层
        layer.open({
            type: 2,
            title: '选择属性信息',
            fix: false, //不固定
            maxmin: true,
            shadeClose: false,//是否点击遮罩关闭弹窗
            shade: 0.2,
            area: ['90%', '90%'],
            content: "{:url('admin/globalFun/chooseShuxing')}?paramcon=btnamecon&paramids=btnameids&id=" + id,
            btn: ['确定', '取消'],
            btn1: function (index, obj1) {
                window[obj1.find('iframe')[0]['name']].getAllcheck();
                $(obj).parent().find('input').val($("#btnameids").val());
                $(obj).parent().prev().find('input').val($("#btnamecon").val());
            }
        });
    }

    //监听提交
    form.on('submit(demo1)', function (data) {
        layer.alert(JSON.stringify(data.field), {
            title: '最终的提交信息'
        })
        return false;
    });

    $(document).ready(function () {
        bindListener();
        for(var i=1;i<id;i++){
            picupload("#bupload"+i, i)
        }
    });

    function p_admin_show(title,url){
        parent.layer.open({
            type: 2,
            area: ['90%', '90%'],
            fix: false, //不固定
            maxmin: true,
            shadeClose: false,//是否点击遮罩关闭弹窗
            shade:0.2,
            resize:true,
            title: title,
            content: url
        });
    }

    function ajaxSubmitForm() {
        var options = {
            type: 'post',           //post提交
            //url:'http://ask.tongzhuo100.com/server/****.php?='+Math.random(),   //url
            dataType: "json",        //json格式
            data: {},    //如果需要提交附加参数，视情况添加
            clearForm: false,        //成功提交后，清除所有表单元素的值
            resetForm: false,        //成功提交后，重置所有表单元素的值
            cache: false,
            async: false,          //同步返回
            success: function (data) {
                // console.log(data);
                if (data.code == 0) {
                    layer.msg(data.msg);
                } else {
                    layer.msg(data.msg, {icon: 1, time: 500}, function () {
                        $("#reset").click();
                        x_admin_close();
                        parent.location.reload();
                    });
                }
                //服务器端返回处理逻辑
            },
            error: function (XmlHttpRequest, textStatus, errorThrown) {
                layer.msg('操作失败:服务器处理失败');
            }
        };
        // bind form using 'ajaxForm'


        $('#mainForm').ajaxForm(options).submit(function (data) {
            //无逻辑
        });
        return false;
    }

    //添加变体
    function addimg() {
        var html = '<tbody><tr><td><div style="float: left;width: 85%">';
        html += '<input type="text" id="btname[]" name="btname[]" class="layui-input" lay-verify="required">';
        html += '</div><div style="float: right;width: 10%;">';
        html += '<input type="hidden" name="btname_id[]" id="btname_id[]" value="">';
        html += '<a href="javascript:void(0);" class="layui-btn layui-btn-xs layui-btn-normal choose" onclick="btchoose(this)">选择</a>';
        html += '<a href="javascript:void(0);" class="layui-btn layui-btn-xs layui-btn-primary choose" onclick="cbtname(this)">清除</a>';
        html += '</div></td>';
        html += '<td><input type="number" id="btprice[]" name="btprice[]" class="layui-input" min="0" step="0.01"></td>';
        html += '<td><input type="number" id="btsaleprice[]" name="btsaleprice[]" class="layui-input" min="0" step="0.01" lay-verify="required"></td>';
        html += '<td><input type="number" id="bcost[]" name="bcost[]" class="layui-input" min="0" step="0.01"></td>';
        html += '<td><input type="number" id="bcarriage[]" name="bcarriage[]" class="layui-input" min="0" step="0.01"></td>';
        html += '<td><input type="number" id="btkucun[]" name="btkucun[]" class="layui-input" min="1" value="1"></td>';
        html += '<td rowspan="2">';
        html += '<button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="bpull(' + id + ')">';
        html += '<i class="layui-icon">&#xe64c;</i>主图拉取</button><br><br>';
        html += '<button type="button" class="layui-btn layui-btn-sm" id="bupload' + id + '">';
        html += '<i class="layui-icon">&#xe67c;</i>新增图片</button><br><br>';
        html += '<input name="imgid[]" type="hidden" id="imgid[]" value="' + id + '" />';

        html += '<a class="layui-btn layui-btn-sm layui-btn-danger" href="javascript:void(0);" name="rmlink"><i class="layui-icon">&#xe640;</i>删除变体</a></td>';
        html += '</tr><tr><td colspan="6"><div id="myimg' + id + '"></div></td></tr></tbody>';
        $("#mdiv").append(html);
        picupload("#bupload"+id, id)
        id++;
        // 为新元素节点添加事件侦听器
        bindListener();
    }


    // 用来绑定事件(使用unbind避免重复绑定)
    function bindListener() {
        $("a[name=rmlink]").unbind().click(function () {
            $(this).parent().parent().parent().remove();
            //id--;
        });
        $("a[name=delimg]").unbind().click(function () {
            $(this).parent().remove();

        });
    }

    function plprice(form) {
        for (var i = 0; i < form.elements.length; i++) {
            var e = form.elements[i];
            if (e.name == "btsaleprice[]" && e.disabled != true)
                e.value = form.zbtsaleprice.value;
        }
    }

    function plkucun(form) {
        for (var i = 0; i < form.elements.length; i++) {
            var e = form.elements[i];
            if (e.name == "btkucun[]" && e.disabled != true)
                e.value = form.plbtkucun.value;
        }
    }

    //主图
    upload.render({
        elem: '#jiaimg' //绑定元素
        , url: 'uploade.html' //上传接口
        , accept: 'images'
        , field: 'imgs'
        , acceptMime:'image/*'
        , multiple:true
        , before: function (obj) { //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
            layer.load(0, {shade: [0.3, '#000']}); //上传loading
        }
        ,done: function(data){
            //上传完毕回调
            if(data.res){
                layer.msg(data.msg);
                layer.closeAll('loading');

                var html = '<div class="btdiv">';
                html += '<input name="pname[]" type="hidden" id="pname[]" class="name" value="' + data.files.name + '"/>';
                html += '<input name="proimg[]" type="hidden" id="proimg[]" class="path" value="' + data.files.path + '"/>';
                html += '<input name="psize[]" type="hidden" id="psize[]" class="size" value="' + data.files.size + '"/>';
                if(data.files.rsize == true) {
                    html += '<input name="ppsize[]" type="hidden" id="ppsize[]" value="' + data.files.size + '"/>';
                }
                html += '<input name="ppostfix[]" type="hidden" id="ppostfix[]" class="postfix" value="' + data.files.postfix + '"/>';
                html += '<input name="poriginal[]" type="hidden" id="poriginal[]" class="original" value="' + data.files.original + '"/>';
                html += '<img src="' + data.files.path + '" onclick="previewImg(this)">';
                html += '<input type="number" name="px[]" required placeholder="排序从小到大" class="layui-input" style="height: 25px;" value="0" min="0">';
                html += '<a class="bupload chooseimg"  href="uploadImg.html?filename=' + data.files.path + '">下载</a>';
                html += '<a href="javascript:void(0);" class="bdel chooseimg" name="delimg">删除</a>';
                html += '<a class="btool chooseimg" onclick="p_admin_show(\'去水印\',\'imgtool.html?img='+ data.files.path +' \')">去水印</a>';

                html += '</div>';

                $("#productimg").append(html);
                bindListener();
            }else{
                layer.msg(data.msg);
                layer.closeAll('loading');
            }
        }
        ,error: function(){
            //请求异常回调
        }
    });

    //上传变体图
    picupload("#bupload", num)
    function picupload(elem,id) {
        upload.render({
            elem: elem //绑定元素
            , url: 'uploade.html' //上传接口
            , accept: 'images'
            , field: 'imgs'
            , acceptMime:'image/*'
            , multiple:true
            , before: function (obj) { //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                layer.load(0, {shade: [0.3, '#000']}); //上传loading
            }
            ,done: function(data){
                //上传完毕回调
                if(data.res){
                    layer.msg(data.msg);
                    layer.closeAll('loading');
                    var html = '<div class="btdiv">';
                    html += '<input name="bname' + id + '[]" type="hidden" id="bname' + id + '[]" value="' + data.files.name + '"/>';
                    html += '<input name="btimg' + id + '[]" type="hidden" id="btimg' + id + '[]" value="' + data.files.path + '"/>';
                    html += '<input name="bsize' + id + '[]" type="hidden" id="bsize' + id + '[]" value="' + data.files.size + '"/>';
                    if(data.files.rsize == true) {
                        html += '<input name="bbsize' + id + '[]" type="hidden" id="bbsize' + id + '[]" value="' + data.files.size + '"/>';
                    }
                    html += '<input name="bpostfix' + id + '[]" type="hidden" id="bpostfix' + id + '[]" value="' + data.files.postfix + '"/>';
                    html += '<input name="boriginal' + id + '[]" type="hidden" id="boriginal' + id + '[]" value="' + data.files.original + '"/>';
                    html += '<img src="' + data.files.path + '" style="float: left;" onclick="previewImg(this)">';
                    html += '<input type="number" name="bpx' + id + '[]" required placeholder="排序从小到大" class="layui-input" style="height: 25px;" value="0" min="0">';
                    html += '<a class="bupload chooseimg"  href="uploadImg.html?filename=' + data.files.path + '">下载</a>';
                    html += '<a href="javascript:void(0);" class="bdel chooseimg" name="delimg">删除</a>';
                    html += '<a class="btool chooseimg" onclick="p_admin_show(\'去水印\',\'imgtool.html?img=' + data.files.path + ' \')">去水印</a>';
                    html += '</div>';
                    $("#myimg" + id).append(html);
                    bindListener();
                }else{
                    layer.msg(data.msg);
                    layer.closeAll('loading');
                }
            }
            ,error: function(){
                //请求异常回调
            }
        });
    }
    //拉取主图
    function bpull(id) {
        $('#productimg div').each(function(i){
            var name = $(this).find('.name').val();
            var path = $(this).find('.path').val();
            var size = $(this).find('.size').val();
            var postfix = $(this).find('.postfix').val();
            var original = $(this).find('.original').val();

            var html = '<div class="btdiv">';
            html += '<input name="bname' + id + '[]" type="hidden" id="bname' + id + '[]" value="' + name + '"/>';
            html += '<input name="btimg' + id + '[]" type="hidden" id="btimg' + id + '[]" value="' + path + '"/>';
            html += '<input name="bsize' + id + '[]" type="hidden" id="bsize' + id + '[]" value="' + size + '"/>';
            html += '<input name="bpostfix' + id + '[]" type="hidden" id="bpostfix' + id + '[]" value="' + postfix + '"/>';
            html += '<input name="boriginal' + id + '[]" type="hidden" id="boriginal' + id + '[]" value="' + original + '"/>';
            html += '<img src="' + path + '" style="float: left;" onclick="previewImg(this)">';
            html += '<input type="number" name="bpx' + id + '[]" required placeholder="排序从小到大" class="layui-input" style="height: 25px;" value="0" min="0">';
            html += '<a class="bupload chooseimg"  href="uploadImg.html?filename=' + path + '">下载</a>';
            html += '<a href="javascript:void(0);" class="bdel chooseimg" name="delimg">删除</a>';
            html += '<a class="btool chooseimg" onclick="p_admin_show(\'去水印\',\'imgtool.html?img=' + path + ' \')">去水印</a>';
            html += '</div>';
            $("#myimg" + id).append(html);
            bindListener();
        })

    }
</script>
